package progetto3.managerAB;

public class ManagerMJ extends ManagerAB {
	
	
	private Object lock = new Object();

	@Override
	public void request(MyRunnable r) {
		synchronized (lock) {
			while(!canPass(r)){
				w++;
				try {
					lock.wait();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				w--;
			}
			entered(r);
		}// lock
	}// request

	@Override
	public void release(MyRunnable r) {
		synchronized (lock) {
			exited(r);
			if(w>0)
				lock.notifyAll();
		}
	}// release
}// ManagerMJ
